home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / js / jscntxt.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  27KB  |  728 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is Mozilla Communicator client code, released
  17.  * March 31, 1998.
  18.  *
  19.  * The Initial Developer of the Original Code is
  20.  * Netscape Communications Corporation.
  21.  * Portions created by the Initial Developer are Copyright (C) 1998
  22.  * the Initial Developer. All Rights Reserved.
  23.  *
  24.  * Contributor(s):
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  28.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. #ifndef jscntxt_h___
  41. #define jscntxt_h___
  42. /*
  43.  * JS execution context.
  44.  */
  45. #include "jsarena.h" /* Added by JSIFY */
  46. #include "jsclist.h"
  47. #include "jslong.h"
  48. #include "jsatom.h"
  49. #include "jsconfig.h"
  50. #include "jsdhash.h"
  51. #include "jsgc.h"
  52. #include "jsinterp.h"
  53. #include "jsobj.h"
  54. #include "jsprvtd.h"
  55. #include "jspubtd.h"
  56. #include "jsregexp.h"
  57.  
  58. JS_BEGIN_EXTERN_C
  59.  
  60. typedef enum JSGCMode { JS_NO_GC, JS_MAYBE_GC, JS_FORCE_GC } JSGCMode;
  61.  
  62. typedef enum JSRuntimeState {
  63.     JSRTS_DOWN,
  64.     JSRTS_LAUNCHING,
  65.     JSRTS_UP,
  66.     JSRTS_LANDING
  67. } JSRuntimeState;
  68.  
  69. typedef struct JSPropertyTreeEntry {
  70.     JSDHashEntryHdr     hdr;
  71.     JSScopeProperty     *child;
  72. } JSPropertyTreeEntry;
  73.  
  74. struct JSRuntime {
  75.     /* Runtime state, synchronized by the stateChange/gcLock condvar/lock. */
  76.     JSRuntimeState      state;
  77.  
  78.     /* Garbage collector state, used by jsgc.c. */
  79.     JSArenaPool         gcArenaPool[GC_NUM_FREELISTS];
  80.     JSGCThing           *gcFreeList[GC_NUM_FREELISTS];
  81.     JSDHashTable        gcRootsHash;
  82.     JSDHashTable        *gcLocksHash;
  83.     jsrefcount          gcKeepAtoms;
  84.     uint32              gcBytes;
  85.     uint32              gcLastBytes;
  86.     uint32              gcMaxBytes;
  87.     uint32              gcMaxMallocBytes;
  88.     uint32              gcLevel;
  89.     uint32              gcNumber;
  90.     JSPackedBool        gcPoke;
  91.     JSPackedBool        gcRunning;
  92.     JSGCCallback        gcCallback;
  93.     uint32              gcMallocBytes;
  94.  
  95.     /*
  96.      * API compatibility requires keeping GCX_PRIVATE bytes separate from the
  97.      * original GC types' byte tally.  Otherwise embeddings that configure a
  98.      * good limit for pre-GCX_PRIVATE versions of the engine will see memory
  99.      * over-pressure too often, possibly leading to failed last-ditch GCs.
  100.      *
  101.      * The new XML GC-thing types do add to gcBytes, and they're larger than
  102.      * the original GC-thing type size (8 bytes on most architectures).  So a
  103.      * user who enables E4X may want to increase the maxbytes value passed to
  104.      * JS_NewRuntime.  TODO: Note this in the API docs.
  105.      */
  106.     uint32              gcPrivateBytes;
  107.  
  108. #if JS_HAS_XML_SUPPORT
  109.     /* Lists of JSXML private data structures to be finalized. */
  110.     JSXMLNamespace      *gcDoomedNamespaces;
  111.     JSXMLQName          *gcDoomedQNames;
  112.     JSXML               *gcDoomedXML;
  113. #endif
  114. #ifdef JS_GCMETER
  115.     JSGCStats           gcStats;
  116. #endif
  117.  
  118.     /* Literal table maintained by jsatom.c functions. */
  119.     JSAtomState         atomState;
  120.  
  121.     /* Random number generator state, used by jsmath.c. */
  122.     JSBool              rngInitialized;
  123.     int64               rngMultiplier;
  124.     int64               rngAddend;
  125.     int64               rngMask;
  126.     int64               rngSeed;
  127.     jsdouble            rngDscale;
  128.  
  129.     /* Well-known numbers held for use by this runtime's contexts. */
  130.     jsdouble            *jsNaN;
  131.     jsdouble            *jsNegativeInfinity;
  132.     jsdouble            *jsPositiveInfinity;
  133.  
  134.     /* Empty string held for use by this runtime's contexts. */
  135.     JSString            *emptyString;
  136.  
  137.     /* List of active contexts sharing this runtime; protected by gcLock. */
  138.     JSCList             contextList;
  139.  
  140.     /* These are used for debugging -- see jsprvtd.h and jsdbgapi.h. */
  141.     JSTrapHandler       interruptHandler;
  142.     void                *interruptHandlerData;
  143.     JSNewScriptHook     newScriptHook;
  144.     void                *newScriptHookData;
  145.     JSDestroyScriptHook destroyScriptHook;
  146.     void                *destroyScriptHookData;
  147.     JSTrapHandler       debuggerHandler;
  148.     void                *debuggerHandlerData;
  149.     JSSourceHandler     sourceHandler;
  150.     void                *sourceHandlerData;
  151.     JSInterpreterHook   executeHook;
  152.     void                *executeHookData;
  153.     JSInterpreterHook   callHook;
  154.     void                *callHookData;
  155.     JSObjectHook        objectHook;
  156.     void                *objectHookData;
  157.     JSTrapHandler       throwHook;
  158.     void                *throwHookData;
  159.     JSDebugErrorHook    debugErrorHook;
  160.     void                *debugErrorHookData;
  161.  
  162.     /* More debugging state, see jsdbgapi.c. */
  163.     JSCList             trapList;
  164.     JSCList             watchPointList;
  165.  
  166.     /* Weak links to properties, indexed by quickened get/set opcodes. */
  167.     /* XXX must come after JSCLists or MSVC alignment bug bites empty lists */
  168.     JSPropertyCache     propertyCache;
  169.  
  170.     /* Client opaque pointer */
  171.     void                *data;
  172.  
  173. #ifdef JS_THREADSAFE
  174.     /* These combine to interlock the GC and new requests. */
  175.     PRLock              *gcLock;
  176.     PRCondVar           *gcDone;
  177.     PRCondVar           *requestDone;
  178.     uint32              requestCount;
  179.     jsword              gcThread;
  180.  
  181.     /* Lock and owning thread pointer for JS_LOCK_RUNTIME. */
  182.     PRLock              *rtLock;
  183. #ifdef DEBUG
  184.     jsword              rtLockOwner;
  185. #endif
  186.  
  187.     /* Used to synchronize down/up state change; protected by gcLock. */
  188.     PRCondVar           *stateChange;
  189.  
  190.     /* Used to serialize cycle checks when setting __proto__ or __parent__. */
  191.     PRLock              *setSlotLock;
  192.     PRCondVar           *setSlotDone;
  193.     JSBool              setSlotBusy;
  194.     JSScope             *setSlotScope;  /* deadlock avoidance, see jslock.c */
  195.  
  196.     /*
  197.      * State for sharing single-threaded scopes, once a second thread tries to
  198.      * lock a scope.  The scopeSharingDone condvar is protected by rt->gcLock,
  199.      * to minimize number of locks taken in JS_EndRequest.
  200.      *
  201.      * The scopeSharingTodo linked list is likewise "global" per runtime, not
  202.      * one-list-per-context, to conserve space over all contexts, optimizing
  203.      * for the likely case that scopes become shared rarely, and among a very
  204.      * small set of threads (contexts).
  205.      */
  206.     PRCondVar           *scopeSharingDone;
  207.     JSScope             *scopeSharingTodo;
  208.  
  209. /*
  210.  * Magic terminator for the rt->scopeSharingTodo linked list, threaded through
  211.  * scope->u.link.  This hack allows us to test whether a scope is on the list
  212.  * by asking whether scope->u.link is non-null.  We use a large, likely bogus
  213.  * pointer here to distinguish this value from any valid u.count (small int)
  214.  * value.
  215.  */
  216. #define NO_SCOPE_SHARING_TODO   ((JSScope *) 0xfeedbeef)
  217. #endif /* JS_THREADSAFE */
  218.  
  219.     /*
  220.      * Check property accessibility for objects of arbitrary class.  Used at
  221.      * present to check f.caller accessibility for any function object f.
  222.      */
  223.     JSCheckAccessOp     checkObjectAccess;
  224.  
  225.     /* Security principals serialization support. */
  226.     JSPrincipalsTranscoder principalsTranscoder;
  227.  
  228.     /* Optional hook to find principals for an object in this runtime. */
  229.     JSObjectPrincipalsFinder findObjectPrincipals;
  230.  
  231.     /* Shared scope property tree, and allocator for its nodes. */
  232.     JSDHashTable        propertyTreeHash;
  233.     JSScopeProperty     *propertyFreeList;
  234.     JSArenaPool         propertyArenaPool;
  235.  
  236.     /* Script filename table. */
  237.     struct JSHashTable  *scriptFilenameTable;
  238.     JSCList             scriptFilenamePrefixes;
  239. #ifdef JS_THREADSAFE
  240.     PRLock              *scriptFilenameTableLock;
  241. #endif
  242.  
  243.     /* Number localization, used by jsnum.c */
  244.     const char          *thousandsSeparator;
  245.     const char          *decimalSeparator;
  246.     const char          *numGrouping;
  247.  
  248.     /*
  249.      * Weak references to lazily-created, well-known XML singletons.
  250.      *
  251.      * NB: Singleton objects must be carefully disconnected from the rest of
  252.      * the object graph usually associated with a JSContext's global object,
  253.      * including the set of standard class objects.  See jsxml.c for details.
  254.      */
  255.     JSObject            *anynameObject;
  256.     JSObject            *functionNamespaceObject;
  257.  
  258. #ifdef DEBUG
  259.     /* Function invocation metering. */
  260.     jsrefcount          inlineCalls;
  261.     jsrefcount          nativeCalls;
  262.     jsrefcount          nonInlineCalls;
  263.     jsrefcount          constructs;
  264.  
  265.     /* Scope lock and property metering. */
  266.     jsrefcount          claimAttempts;
  267.     jsrefcount          claimedScopes;
  268.     jsrefcount          deadContexts;
  269.     jsrefcount          deadlocksAvoided;
  270.     jsrefcount          liveScopes;
  271.     jsrefcount          sharedScopes;
  272.     jsrefcount          totalScopes;
  273.     jsrefcount          badUndependStrings;
  274.     jsrefcount          liveScopeProps;
  275.     jsrefcount          totalScopeProps;
  276.     jsrefcount          livePropTreeNodes;
  277.     jsrefcount          duplicatePropTreeNodes;
  278.     jsrefcount          totalPropTreeNodes;
  279.     jsrefcount          propTreeKidsChunks;
  280.     jsrefcount          middleDeleteFixups;
  281.  
  282.     /* String instrumentation. */
  283.     jsrefcount          liveStrings;
  284.     jsrefcount          totalStrings;
  285.     jsrefcount          liveDependentStrings;
  286.     jsrefcount          totalDependentStrings;
  287.     double              lengthSum;
  288.     double              lengthSquaredSum;
  289.     double              strdepLengthSum;
  290.     double              strdepLengthSquaredSum;
  291. #endif
  292. };
  293.  
  294. #ifdef DEBUG
  295. # define JS_RUNTIME_METER(rt, which)    JS_ATOMIC_INCREMENT(&(rt)->which)
  296. # define JS_RUNTIME_UNMETER(rt, which)  JS_ATOMIC_DECREMENT(&(rt)->which)
  297. #else
  298. # define JS_RUNTIME_METER(rt, which)    /* nothing */
  299. # define JS_RUNTIME_UNMETER(rt, which)  /* nothing */
  300. #endif
  301.  
  302. #define JS_KEEP_ATOMS(rt)   JS_ATOMIC_INCREMENT(&(rt)->gcKeepAtoms);
  303. #define JS_UNKEEP_ATOMS(rt) JS_ATOMIC_DECREMENT(&(rt)->gcKeepAtoms);
  304.  
  305. #ifdef JS_ARGUMENT_FORMATTER_DEFINED
  306. /*
  307.  * Linked list mapping format strings for JS_{Convert,Push}Arguments{,VA} to
  308.  * formatter functions.  Elements are sorted in non-increasing format string
  309.  * length order.
  310.  */
  311. struct JSArgumentFormatMap {
  312.     const char          *format;
  313.     size_t              length;
  314.     JSArgumentFormatter formatter;
  315.     JSArgumentFormatMap *next;
  316. };
  317. #endif
  318.  
  319. struct JSStackHeader {
  320.     uintN               nslots;
  321.     JSStackHeader       *down;
  322. };
  323.  
  324. #define JS_STACK_SEGMENT(sh)    ((jsval *)(sh) + 2)
  325.  
  326. /*
  327.  * Key and entry types for the JSContext.resolvingTable hash table, typedef'd
  328.  * here because all consumers need to see these declarations (and not just the
  329.  * typedef names, as would be the case for an opaque pointer-to-typedef'd-type
  330.  * declaration), along with cx->resolvingTable.
  331.  */
  332. typedef struct JSResolvingKey {
  333.     JSObject            *obj;
  334.     jsid                id;
  335. } JSResolvingKey;
  336.  
  337. typedef struct JSResolvingEntry {
  338.     JSDHashEntryHdr     hdr;
  339.     JSResolvingKey      key;
  340.     uint32              flags;
  341. } JSResolvingEntry;
  342.  
  343. #define JSRESFLAG_LOOKUP        0x1     /* resolving id from lookup */
  344. #define JSRESFLAG_WATCH         0x2     /* resolving id from watch */
  345.  
  346. typedef struct JSLocalRootChunk JSLocalRootChunk;
  347.  
  348. #define JSLRS_CHUNK_SHIFT       8
  349. #define JSLRS_CHUNK_SIZE        JS_BIT(JSLRS_CHUNK_SHIFT)
  350. #define JSLRS_CHUNK_MASK        JS_BITMASK(JSLRS_CHUNK_SHIFT)
  351.  
  352. struct JSLocalRootChunk {
  353.     jsval               roots[JSLRS_CHUNK_SIZE];
  354.     JSLocalRootChunk    *down;
  355. };
  356.  
  357. typedef struct JSLocalRootStack {
  358.     uint32              scopeMark;
  359.     uint32              rootCount;
  360.     JSLocalRootChunk    *topChunk;
  361.     JSLocalRootChunk    firstChunk;
  362. } JSLocalRootStack;
  363.  
  364. #define JSLRS_NULL_MARK ((uint32) -1)
  365.  
  366. typedef struct JSTempValueRooter JSTempValueRooter;
  367.  
  368. /*
  369.  * If count is -1, then u.value contains the single value to root.  Otherwise
  370.  * u.array points to a stack-allocated vector of jsvals.  Note that the vector
  371.  * may have length 0 or 1 for full generality, so we need -1 to discriminate
  372.  * the union.
  373.  *
  374.  * If you need to protect a result value that flows out of a C function across
  375.  * several layers of other functions, use the js_LeaveLocalRootScopeWithResult
  376.  * internal API (see further below) instead.
  377.  */
  378. struct JSTempValueRooter {
  379.     JSTempValueRooter   *down;
  380.     jsint               count;
  381.     union {
  382.         jsval           value;
  383.         jsval           *array;
  384.     } u;
  385. };
  386.  
  387. #define JS_PUSH_TEMP_ROOT_COMMON(cx,tvr)                                      \
  388.     JS_BEGIN_MACRO                                                            \
  389.         JS_ASSERT((cx)->tempValueRooters != (tvr));                           \
  390.         (tvr)->down = (cx)->tempValueRooters;                                 \
  391.         (cx)->tempValueRooters = (tvr);                                       \
  392.     JS_END_MACRO
  393.  
  394. #define JS_PUSH_SINGLE_TEMP_ROOT(cx,val,tvr)                                  \
  395.     JS_BEGIN_MACRO                                                            \
  396.         JS_PUSH_TEMP_ROOT_COMMON(cx, tvr);                                    \
  397.         (tvr)->count = -1;                                                    \
  398.         (tvr)->u.value = (val);                                               \
  399.     JS_END_MACRO
  400.  
  401. #define JS_PUSH_TEMP_ROOT(cx,cnt,arr,tvr)                                     \
  402.     JS_BEGIN_MACRO                                                            \
  403.         JS_PUSH_TEMP_ROOT_COMMON(cx, tvr);                                    \
  404.         (tvr)->count = (cnt);                                                 \
  405.         (tvr)->u.array = (arr);                                               \
  406.     JS_END_MACRO
  407.  
  408. #define JS_POP_TEMP_ROOT(cx,tvr)                                              \
  409.     JS_BEGIN_MACRO                                                            \
  410.         JS_ASSERT((cx)->tempValueRooters == (tvr));                           \
  411.         (cx)->tempValueRooters = (tvr)->down;                                 \
  412.     JS_END_MACRO
  413.  
  414. #define JS_TEMP_ROOT_EVAL(cx,cnt,val,expr)                                    \
  415.     JS_BEGIN_MACRO                                                            \
  416.         JSTempValueRooter tvr;                                                \
  417.         JS_PUSH_TEMP_ROOT(cx, cnt, val, &tvr);                                \
  418.         (expr);                                                               \
  419.         JS_POP_TEMP_ROOT(cx, &tvr);                                           \
  420.     JS_END_MACRO
  421.  
  422. struct JSContext {
  423.     JSCList             links;
  424.  
  425.     /* Interpreter activation count. */
  426.     uintN               interpLevel;
  427.  
  428.     /* Limit pointer for checking stack consumption during recursion. */
  429.     jsuword             stackLimit;
  430.  
  431.     /* Runtime version control identifier and equality operators. */
  432.     uint16              version;
  433.     jsbytecode          jsop_eq;
  434.     jsbytecode          jsop_ne;
  435.  
  436.     /* Data shared by threads in an address space. */
  437.     JSRuntime           *runtime;
  438.  
  439.     /* Stack arena pool and frame pointer register. */
  440.     JSArenaPool         stackPool;
  441.     JSStackFrame        *fp;
  442.  
  443.     /* Temporary arena pool used while compiling and decompiling. */
  444.     JSArenaPool         tempPool;
  445.  
  446.     /* Top-level object and pointer to top stack frame's scope chain. */
  447.     JSObject            *globalObject;
  448.  
  449.     /* Most recently created things by type, members of the GC's root set. */
  450.     JSGCThing           *newborn[GCX_NTYPES];
  451.  
  452.     /* Atom root for the last-looked-up atom on this context. */
  453.     JSAtom              *lastAtom;
  454.  
  455.     /* Root for the result of the most recent js_InternalInvoke call. */
  456.     jsval               lastInternalResult;
  457.  
  458.     /* Regular expression class statics (XXX not shared globally). */
  459.     JSRegExpStatics     regExpStatics;
  460.  
  461.     /* State for object and array toSource conversion. */
  462.     JSSharpObjectMap    sharpObjectMap;
  463.  
  464.     /* Argument formatter support for JS_{Convert,Push}Arguments{,VA}. */
  465.     JSArgumentFormatMap *argumentFormatMap;
  466.  
  467.     /* Last message string and trace file for debugging. */
  468.     char                *lastMessage;
  469. #ifdef DEBUG
  470.     void                *tracefp;
  471. #endif
  472.  
  473.     /* Per-context optional user callbacks. */
  474.     JSBranchCallback    branchCallback;
  475.     JSErrorReporter     errorReporter;
  476.  
  477.     /* Client opaque pointer */
  478.     void                *data;
  479.  
  480.     /* GC and thread-safe state. */
  481.     JSStackFrame        *dormantFrameChain; /* dormant stack frame to scan */
  482. #ifdef JS_THREADSAFE
  483.     jsword              thread;
  484.     jsrefcount          requestDepth;
  485.     JSScope             *scopeToShare;      /* weak reference, see jslock.c */
  486.     JSScope             *lockedSealedScope; /* weak ref, for low-cost sealed
  487.                                                scope locking */
  488. #endif
  489.  
  490. #if JS_HAS_LVALUE_RETURN
  491.     /*
  492.      * Secondary return value from native method called on the left-hand side
  493.      * of an assignment operator.  The native should store the object in which
  494.      * to set a property in *rval, and return the property's id expressed as a
  495.      * jsval by calling JS_SetCallReturnValue2(cx, idval).
  496.      */
  497.     jsval               rval2;
  498.     JSPackedBool        rval2set;
  499. #endif
  500.  
  501. #if JS_HAS_XML_SUPPORT
  502.     /*
  503.      * Bit-set formed from binary exponentials of the XML_* tiny-ids defined
  504.      * for boolean settings in jsxml.c, plus an XSF_CACHE_VALID bit.  Together
  505.      * these act as a cache of the boolean XML.ignore* and XML.prettyPrinting
  506.      * property values associated with this context's global object.
  507.      */
  508.     uint8               xmlSettingFlags;
  509. #endif
  510.  
  511.     /*
  512.      * True if creating an exception object, to prevent runaway recursion.
  513.      * NB: creatingException packs with rval2set, #if JS_HAS_LVALUE_RETURN;
  514.      * with xmlSettingFlags, #if JS_HAS_XML_SUPPORT; and with throwing below.
  515.      */
  516.     JSPackedBool        creatingException;
  517.  
  518.     /*
  519.      * Exception state -- the exception member is a GC root by definition.
  520.      * NB: throwing packs with creatingException and rval2set, above.
  521.      */
  522.     JSPackedBool        throwing;           /* is there a pending exception? */
  523.     jsval               exception;          /* most-recently-thrown exception */
  524.  
  525.     /* Per-context options. */
  526.     uint32              options;            /* see jsapi.h for JSOPTION_* */
  527.  
  528.     /* Locale specific callbacks for string conversion. */
  529.     JSLocaleCallbacks   *localeCallbacks;
  530.  
  531.     /*
  532.      * cx->resolvingTable is non-null and non-empty if we are initializing
  533.      * standard classes lazily, or if we are otherwise recursing indirectly
  534.      * from js_LookupProperty through a JSClass.resolve hook.  It is used to
  535.      * limit runaway recursion (see jsapi.c and jsobj.c).
  536.      */
  537.     JSDHashTable        *resolvingTable;
  538.  
  539.     /* PDL of stack headers describing stack slots not rooted by argv, etc. */
  540.     JSStackHeader       *stackHeaders;
  541.  
  542.     /* Optional stack of heap-allocated scoped local GC roots. */
  543.     JSLocalRootStack    *localRootStack;
  544.  
  545.     /* Stack of thread-stack-allocated temporary GC roots. */
  546.     JSTempValueRooter   *tempValueRooters;
  547. };
  548.  
  549. /*
  550.  * Slightly more readable macros for testing per-context option settings (also
  551.  * to hide bitset implementation detail).
  552.  *
  553.  * JSOPTION_XML must be handled specially in order to propagate from compile-
  554.  * to run-time (from cx->options to script->version/cx->version).  To do that,
  555.  * we copy JSOPTION_XML from cx->options into cx->version as JSVERSION_HAS_XML
  556.  * whenever options are set, and preserve this XML flag across version number
  557.  * changes done via the JS_SetVersion API.
  558.  *
  559.  * But when executing a script or scripted function, the interpreter changes
  560.  * cx->version, including the XML flag, to script->version.  Thus JSOPTION_XML
  561.  * is a compile-time option that causes a run-time version change during each
  562.  * activation of the compiled script.  That version change has the effect of
  563.  * changing JS_HAS_XML_OPTION, so that any compiling done via eval enables XML
  564.  * support.  If an XML-enabled script or function calls a non-XML function,
  565.  * the flag bit will be cleared during the callee's activation.
  566.  *
  567.  * Note that JS_SetVersion API calls never pass JSVERSION_HAS_XML or'd into
  568.  * that API's version parameter.
  569.  * 
  570.  * Note also that script->version must contain this XML option flag in order
  571.  * for XDR'ed scripts to serialize and deserialize with that option preserved
  572.  * for detection at run-time.  We can't copy other compile-time options into
  573.  * script->version because that would break backward compatibility (certain
  574.  * other options, e.g. JSOPTION_VAROBJFIX, are analogous to JSOPTION_XML).
  575.  */
  576. #define JS_HAS_OPTION(cx,option)        (((cx)->options & (option)) != 0)
  577. #define JS_HAS_STRICT_OPTION(cx)        JS_HAS_OPTION(cx, JSOPTION_STRICT)
  578. #define JS_HAS_WERROR_OPTION(cx)        JS_HAS_OPTION(cx, JSOPTION_WERROR)
  579. #define JS_HAS_COMPILE_N_GO_OPTION(cx)  JS_HAS_OPTION(cx, JSOPTION_COMPILE_N_GO)
  580. #define JS_HAS_ATLINE_OPTION(cx)        JS_HAS_OPTION(cx, JSOPTION_ATLINE)
  581.  
  582. #define JSVERSION_MASK                  0x0FFF  /* see JSVersion in jspubtd.h */
  583. #define JSVERSION_HAS_XML               0x1000  /* flag induced by XML option */
  584.  
  585. #define JSVERSION_NUMBER(cx)            ((cx)->version & JSVERSION_MASK)
  586. #define JS_HAS_XML_OPTION(cx)           ((cx)->version & JSVERSION_HAS_XML || \
  587.                                          JSVERSION_NUMBER(cx) >= JSVERSION_1_6)
  588.  
  589. #define JS_HAS_NATIVE_BRANCH_CALLBACK_OPTION(cx)                              \
  590.     JS_HAS_OPTION(cx, JSOPTION_NATIVE_BRANCH_CALLBACK)
  591.  
  592. /*
  593.  * Wrappers for the JSVERSION_IS_* macros from jspubtd.h taking JSContext *cx
  594.  * and masking off the XML flag and any other high order bits.
  595.  */
  596. #define JS_VERSION_IS_ECMA(cx)          JSVERSION_IS_ECMA(JSVERSION_NUMBER(cx))
  597. #define JS_VERSION_IS_1_2(cx)           (JSVERSION_NUMBER(cx) == JSVERSION_1_2)
  598.  
  599. /*
  600.  * Common subroutine of JS_SetVersion and js_SetVersion, to update per-context
  601.  * data that depends on version.
  602.  */
  603. extern void
  604. js_OnVersionChange(JSContext *cx);
  605.  
  606. /*
  607.  * Unlike the JS_SetVersion API, this function stores JSVERSION_HAS_XML and
  608.  * any future non-version-number flags induced by compiler options.
  609.  */
  610. extern void
  611. js_SetVersion(JSContext *cx, JSVersion version);
  612.  
  613. /*
  614.  * Create and destroy functions for JSContext, which is manually allocated
  615.  * and exclusively owned.
  616.  */
  617. extern JSContext *
  618. js_NewContext(JSRuntime *rt, size_t stackChunkSize);
  619.  
  620. extern void
  621. js_DestroyContext(JSContext *cx, JSGCMode gcmode);
  622.  
  623. /*
  624.  * Return true if cx points to a context in rt->contextList, else return false.
  625.  * NB: the caller (see jslock.c:ClaimScope) must hold rt->gcLock.
  626.  */
  627. extern JSBool
  628. js_ValidContextPointer(JSRuntime *rt, JSContext *cx);
  629.  
  630. /*
  631.  * If unlocked, acquire and release rt->gcLock around *iterp update; otherwise
  632.  * the caller must be holding rt->gcLock.
  633.  */
  634. extern JSContext *
  635. js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp);
  636.  
  637. /*
  638.  * JSClass.resolve and watchpoint recursion damping machinery.
  639.  */
  640. extern JSBool
  641. js_StartResolving(JSContext *cx, JSResolvingKey *key, uint32 flag,
  642.                   JSResolvingEntry **entryp);
  643.  
  644. extern void
  645. js_StopResolving(JSContext *cx, JSResolvingKey *key, uint32 flag,
  646.                  JSResolvingEntry *entry, uint32 generation);
  647.  
  648. /*
  649.  * Local root set management.
  650.  */
  651. extern JSBool
  652. js_EnterLocalRootScope(JSContext *cx);
  653.  
  654. extern void
  655. js_LeaveLocalRootScope(JSContext *cx);
  656.  
  657. extern void
  658. js_ForgetLocalRoot(JSContext *cx, jsval v);
  659.  
  660. extern int
  661. js_PushLocalRoot(JSContext *cx, JSLocalRootStack *lrs, jsval v);
  662.  
  663. extern void
  664. js_MarkLocalRoots(JSContext *cx, JSLocalRootStack *lrs);
  665.  
  666. /*
  667.  * Report an exception, which is currently realized as a printf-style format
  668.  * string and its arguments.
  669.  */
  670. typedef enum JSErrNum {
  671. #define MSG_DEF(name, number, count, exception, format) \
  672.     name = number,
  673. #include "js.msg"
  674. #undef MSG_DEF
  675.     JSErr_Limit
  676. } JSErrNum;
  677.  
  678. extern const JSErrorFormatString *
  679. js_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber);
  680.  
  681. #ifdef va_start
  682. extern JSBool
  683. js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap);
  684.  
  685. extern JSBool
  686. js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
  687.                        void *userRef, const uintN errorNumber,
  688.                        JSBool charArgs, va_list ap);
  689.  
  690. extern JSBool
  691. js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
  692.                         void *userRef, const uintN errorNumber,
  693.                         char **message, JSErrorReport *reportp,
  694.                         JSBool *warningp, JSBool charArgs, va_list ap);
  695. #endif
  696.  
  697. extern void
  698. js_ReportOutOfMemory(JSContext *cx, JSErrorCallback errorCallback);
  699.  
  700. /*
  701.  * Report an exception using a previously composed JSErrorReport.
  702.  * XXXbe remove from "friend" API
  703.  */
  704. extern JS_FRIEND_API(void)
  705. js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
  706.  
  707. extern void
  708. js_ReportIsNotDefined(JSContext *cx, const char *name);
  709.  
  710. extern JSErrorFormatString js_ErrorFormatString[JSErr_Limit];
  711.  
  712. /*
  713.  * See JS_SetThreadStackLimit in jsapi.c, where we check that the stack grows
  714.  * in the expected direction.  On Unix-y systems, JS_STACK_GROWTH_DIRECTION is
  715.  * computed on the build host by jscpucfg.c and written into jsautocfg.h.  The
  716.  * macro is hardcoded in jscpucfg.h on Windows and Mac systems (for historical
  717.  * reasons pre-dating autoconf usage).
  718.  */
  719. #if JS_STACK_GROWTH_DIRECTION > 0
  720. # define JS_CHECK_STACK_SIZE(cx, lval)  ((jsuword)&(lval) < (cx)->stackLimit)
  721. #else
  722. # define JS_CHECK_STACK_SIZE(cx, lval)  ((jsuword)&(lval) > (cx)->stackLimit)
  723. #endif
  724.  
  725. JS_END_EXTERN_C
  726.  
  727. #endif /* jscntxt_h___ */
  728.